____ _ _ _ _
| _ \ ___ | |_ (_) _ __ ___ __| | (_) __ _
| |_) | / _ \ | __| | | | '_ \ / _ \ / _| | | | / _ |
| _ < | __/ | |_ | | | |_) | | __/ | (_| | | | | (_| |
|_| \_\ \___| \__| |_| | .__/ \___| \__,_| |_| \__,_|
|_|
- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b
Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―
Math.h
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
top
math.h ist eine Header-Datei in der Standard C Library der Programmiersprache C. Sie wurde fΓΌr mathematische Funktionen entwickelt. Die Programmiersprache C++ benutzt die Funktionen ebenfalls, um die KompatibilitΓ€t von C zu C++ zu gewΓ€hrleisten, und deklariert sie in der Header-Datei cmath (dort ohne die Dateinamenserweiterung β.hβ verwendet).
Alle Funktionen, die einen Winkel einlesen oder ausgeben, arbeiten mit Radiant. Die meisten Funktionen arbeiten mit Gleitkommazahlen. Mathematische Funktionen, die mit ganzzahligen Werten (Integer) arbeiten, wie abv, labs, div oder ldiv, sind stattdessen in der Header-Datei stdlib.h vertreten.
Contents
β’ C99-Funktionen
β’ Beispiel
β’ Weblinks
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Funktionen bis C95
In den Normen bis einschlieΓlich C95 waren die folgenden Funktionen deklariert.
| Name | Beschreibung | Mathematische Formulierung |
|---|---|---|
| acos | Arkuskosinus | arccos β‘ x {\displaystyle \arccos x} |
| asin | Arkussinus | arcsin β‘ x {\displaystyle \arcsin x} |
| atan | Arkustangens | arctan β‘ x {\displaystyle \arctan x} |
| atan2 | βArkustangensβ mit zwei Argumenten | atan2 β‘ ( y , x ) {\displaystyle \operatorname {atan2} (y,x)} |
| ceil | Aufrundungsfunktion | β x β {\displaystyle \lceil x\rceil } |
| cos | Kosinus | cos β‘ x {\displaystyle \cos x} |
| cosh | Kosinus hyperbolicus | cosh β‘ x {\displaystyle \cosh x} |
| exp | Exponentialfunktion | e x {\displaystyle e^{x}} |
| fabs | Betragsfunktion | / x / {\displaystyle /x/} |
| floor | Ganzteilfunktion | β x β {\displaystyle \lfloor x\rfloor } |
| fmod | FΓΌhrt die Modulo -Funktion fΓΌr Gleitkommazahlen durch | x mod y {\displaystyle x{\bmod {y}}} |
| frexp | Teilt eine Gleitkommazahl in Faktor und Potenz mit der Basis 2 auf | |
| ldexp | Multipliziert den ersten Parameter mit 2 um den zweiten Parameter potenziert | x 2 y {\displaystyle x2^{y}} |
| log | NatΓΌrlicher Logarithmus | ln β‘ x {\displaystyle \ln x} |
| log10 | Logarithmus zur Basis 10 | log 10 β‘ x {\displaystyle \log _{10}x} |
| modf | Teilt eine Gleitkommazahl in zwei Zahlen auf, vor und nach dem Komma | |
| pow | Potenziert ersten mit dem zweiten Parameter | x y {\displaystyle x^{y}} |
| sin | Sinus | sin β‘ x {\displaystyle \sin x} |
| sinh | Sinus hyperbolicus | sinh β‘ x {\displaystyle \sinh x} |
| sqrt | Quadratwurzel | x {\displaystyle {\sqrt {x}}} |
| tan | Tangens | tan β‘ x {\displaystyle \tan x} |
| tanh | Tangens hyperbolicus | tanh β‘ x {\displaystyle \tanh x} |
C99-Funktionen
Mit der Norm C99 wurde math.h um die folgenden Funktionen erweitert.
| Name | Beschreibung | Mathematische Formulierung |
|---|---|---|
| acosh | Areakosinus hyperbolicus | arcosh β‘ x {\displaystyle \operatorname {arcosh} x} |
| asinh | Areasinus hyperbolicus | arsinh β‘ x {\displaystyle \operatorname {arsinh} x} |
| atanh | Areatangens hyperbolicus | artanh β‘ x {\displaystyle \operatorname {artanh} x} |
| cbrt | Kubikwurzel | x 3 {\displaystyle {\sqrt[{3}]{x}}} |
| copysign( x , y ) | gibt den Wert von x mit dem Vorzeichen von y zurΓΌck | / x / β
sgn β‘ y {\displaystyle /x/\cdot \operatorname {sgn} y} |
| erf | Fehlerfunktion | erf β‘ x {\displaystyle \operatorname {erf} x} |
| erfc | Gibt den KomplementΓ€rfehler von x zurΓΌck | erfc β‘ x {\displaystyle \operatorname {erfc} x} |
| exp2( x ) | Potenziert 2 mit dem ΓΌbergebenen Parameter | 2 x {\displaystyle 2^{x}} |
| expm1( x ) | Liefert den Wert von exp()-1 zurΓΌck | e x β 1 {\displaystyle e^{x}-1} |
| fdim( x , y ) | Positive Differenz | max ( 0 , x β y ) {\displaystyle \max(0,x-y)} |
| fma( x , y , z ) | Multipliziert und Addiert | x y + z {\displaystyle xy+z} |
| fmax( x , y ) | Maximum | max ( x , y ) {\displaystyle \max(x,y)} |
| fmin( x , y ) | Minimum | min ( x , y ) {\displaystyle \min(x,y)} |
| hypot( x , y ) | Hypotenuse | ( x 2 + y 2 ) {\displaystyle {\sqrt {(x^{2}+y^{2})}}} |
| ilogb | wie logb , gibt allerdings int zurΓΌck | (int)logb(x) |
| lgamma | Logarithmus der Gammafunktion | ln β‘ / Ξ ( x ) / {\displaystyle \ln /\Gamma (x)/} |
| llrint | Rundungsfunktion | |
| lrint | Rundungsfunktion | |
| llround | Rundungsfunktion | |
| lround | Rundungsfunktion | |
| log1p( x ) | NatΓΌrlicher Logarithmus von 1 + x | ln β‘ ( 1 + x ) {\displaystyle \ln(1+x)} |
| log2 | Logarithmus zur Basis 2 | lb β‘ x {\displaystyle \operatorname {lb} x} |
| logb | Liefert den ganzzahligen Exponenten einer Gleitkommazahl als Gleitkommazahl | rint β‘ ( log F L T _ R A D I X β‘ / x / ) {\displaystyle \operatorname {rint} (\log _{\mathrm {FLT\_RADIX} }/x/)} |
| nan( s ) | Ein NaN erzeugen | 0 / 0 {\displaystyle 0/0} |
| nearbyint | Rundet Gleitkommazahlen zum nΓ€chsten Integer | |
| nextafter( x , y ) | Gibt die nΓ€chst darstellbare Zahl nach x (Richtung y ) zurΓΌck | |
| nexttoward( x , y ) | Wie nextafter , auΓer dass y als long double ΓΌbergeben wird | |
| remainder( x , y ) | Rest einer Division | |
| remquo( x , y , p ) | Genauso wie remainder , speichert jedoch den Quotienten (als int ) als Ziel des Zeigers p | |
| rint | Rundet je nach Rundungsmodus zum nΓ€chsten Integer, gibt eine Gleitkommazahl zurΓΌck | |
| round | kaufmΓ€nnische Rundungsfunktion | β x + 0 , 5 β {\displaystyle \lfloor x+0{,}5\rfloor } |
| scalbln( x , y ) | x * FLT_RADIX y ( y ist long ) | x β
F L T _ R A D I X y {\displaystyle x\cdot \mathrm {FLT\_RADIX} ^{y}} |
| scalbn( x , y ) | x * FLT_RADIX y ( y ist int ) | x β
F L T _ R A D I X y {\displaystyle x\cdot \mathrm {FLT\_RADIX} ^{y}} |
| tgamma | Gammafunktion | Ξ ( x ) {\displaystyle \Gamma (x)} |
| trunc | Beschneidet eine Gleitkommazahl, d. h. rundet βRichtung Nullβ | { β x β , x β₯ 0 β x β , x < 0 {\displaystyle {\begin{cases}\lfloor x\rfloor ,&x\geq 0\\\lceil x\rceil ,&x<0\end{cases}}} |
Beispiel
#include <stdio.h>
#include <math.h>
int main() {
double a = 5, b = 4;
double c = pow(a, b);
printf("%f hoch %f ist %f\n", a, b, c);
}
Weblinks
β’ Rationale for International Standard β Programming Languages β C. (PDF, 898 kB) Abgerufen am 4. September 2011 (C99).
β’ Beschreibung auf cplusplus.com (englisch)
β’ Dokumentation von math.h auf dinkumware.com (Memento vom 21. Februar 2010 im Internet Archive)